<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
import { simBusinessStatus } from "@/api/system/info";
export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null,
      using:'',
      test:'',
      silence:''
    }
  },
	created(){
	simBusinessStatus().then((res)=>{  
		console.log(11111);
		console.log(res);
		if(res.code==200){
			this.using = res.using;
			this.test = res.test;
			this.silence = res.silence;
			this.initChart()
	}
  })
	},
  mounted() {
    this.$nextTick(() => {
     
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
  	fomateData(time){
  		return time.substring(0,4)+'年'+time.substring(4,6)+'月'
  	},
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.chart.setOption({
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          left: 'center',
          bottom: '10',
          data: ['正在使用:'+this.using, '测试:'+this.test, '沉默期:'+this.silence]
        },
        series: [
          {
            name: 'SIM卡业务状态',
            type: 'pie',
//          roseType: 'radius',
            radius: [15, 95],
            center: ['50%', '42%'],
            data: [
              { value: this.using, name: '正在使用:'+this.using },
              { value: this.test, name: '测试:'+this.test },
              { value: this.silence, name: '沉默期:'+this.silence},
            ],
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      })
    }
  }
}
</script>
